package com.hd.service.activiti.form.impl;

import com.hd.dao.BaseDao;
import com.hd.entity.activiti.form.FormDesign;
import com.hd.service.activiti.form.FormDesignService;
import com.hd.util.StringUtils;
import com.hd.util.result.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
* 表单设计
*/
@Service("formDesignService")
public class FormDesignServiceImpl implements FormDesignService {
    @Autowired
    private BaseDao<FormDesign,String>formDesignDao;
    @Override
    public void save(FormDesign formDesign) {
		formDesign.setId(UUID.randomUUID().toString());
       formDesignDao.save(formDesign);
    }

    @Override
    public void delete(String id){
      formDesignDao.delete(FormDesign.class,id);
    }
       

    @Override
    public void update(FormDesign formDesign) {
        FormDesign vo=formDesignDao.get(FormDesign.class,formDesign.getId());
        formDesignDao.update(formDesign);
    }
    @Override
    public FormDesign get(String id){
    	return formDesignDao.get(FormDesign.class, id);
    }
        

    @Override
    public void selectDataGrid(PageInfo pageInfo) {
        String hql="from FormDesign where 1=1 ";
        Map<String,Object>condition=pageInfo.getCondition();
        List<Object> params=new ArrayList<Object>();
			if(!StringUtils.isNull(condition.get("title"))) {
            hql+=" and title like ?";
            params.add("%"+condition.get("title")+"%");
        }
        if(!pageInfo.getSort().equals("")) {
            hql+=" order by "+pageInfo.getSort()+" "+pageInfo.getOrder();
        }
        List<FormDesign> formDesigns=formDesignDao.findPage(hql, pageInfo.getNowpage(), pageInfo.getPagesize(),params);
        pageInfo.setRows(formDesigns);
        String countSql="select count(*) "+hql;
        int total=Integer.parseInt(Long.toString(formDesignDao.getCountByList(countSql,params)));
        pageInfo.setTotal(total);
    }



}
